Skip to content

Conversation

dtolnay
Copy link
Member

@dtolnay dtolnay commented Jun 14, 2025

One way to observe the difference between these signatures, using 0 explicit lifetimes and 0 contrived where-clauses:

use std::collections::btree_set::{BTreeSet, ExtractIf};
use std::ops::RangeFull;

fn repro(
    set: &mut BTreeSet<i32>,
    predicate: impl Fn(i32) -> bool,
) -> ExtractIf<i32, RangeFull, impl FnMut(&i32) -> bool> {
    set.extract_if(.., move |x| predicate(*x))
}

Before:

error[E0311]: the parameter type `impl Fn(i32) -> bool` may not live long enough
 --> src/lib.rs:8:5
  |
5 |     set: &mut BTreeSet<i32>,
  |          ------------------ the parameter type `impl Fn(i32) -> bool` must be valid for the anonymous lifetime defined here...
...
8 |     set.extract_if(.., move |x| predicate(*x))
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `impl Fn(i32) -> bool` will meet its required lifetime bounds
  |
help: consider adding an explicit lifetime bound
  |
4 ~ fn repro<'a>(
5 ~     set: &'a mut BTreeSet<i32>,
6 ~     predicate: impl Fn(i32) -> bool + 'a,
7 ~ ) -> ExtractIf<'a, i32, RangeFull, impl FnMut(&i32) -> bool> {
  |

After: compiles successfully.

@rustbot
Copy link
Collaborator

rustbot commented Jun 14, 2025

r? @ibraheemdev

rustbot has assigned @ibraheemdev.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jun 14, 2025
@m-ou-se
Copy link
Member

m-ou-se commented Jun 14, 2025

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Jun 14, 2025

📌 Commit dac9d78 has been approved by m-ou-se

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 14, 2025
jhpratt added a commit to jhpratt/rust that referenced this pull request Jun 14, 2025
Remove unneeded lifetime bound from signature of BTreeSet::extract_if

One way to observe the difference between these signatures, using 0 explicit lifetimes and 0 contrived where-clauses:

```rust
use std::collections::btree_set::{BTreeSet, ExtractIf};
use std::ops::RangeFull;

fn repro(
    set: &mut BTreeSet<i32>,
    predicate: impl Fn(i32) -> bool,
) -> ExtractIf<i32, RangeFull, impl FnMut(&i32) -> bool> {
    set.extract_if(.., move |x| predicate(*x))
}
```

**Before:**

```console
error[E0311]: the parameter type `impl Fn(i32) -> bool` may not live long enough
 --> src/lib.rs:8:5
  |
5 |     set: &mut BTreeSet<i32>,
  |          ------------------ the parameter type `impl Fn(i32) -> bool` must be valid for the anonymous lifetime defined here...
...
8 |     set.extract_if(.., move |x| predicate(*x))
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `impl Fn(i32) -> bool` will meet its required lifetime bounds
  |
help: consider adding an explicit lifetime bound
  |
4 ~ fn repro<'a>(
5 ~     set: &'a mut BTreeSet<i32>,
6 ~     predicate: impl Fn(i32) -> bool + 'a,
7 ~ ) -> ExtractIf<'a, i32, RangeFull, impl FnMut(&i32) -> bool> {
  |
```

**After:** compiles success.

- Tracking issue: rust-lang#70530
bors added a commit that referenced this pull request Jun 14, 2025
Rollup of 9 pull requests

Successful merges:

 - #140593 (Temporary lifetime extension through tuple struct and tuple variant constructors)
 - #141399 ([rustdoc] Give more information into extracted doctest information)
 - #141493 (Delegate `<SocketAddr as Debug>` to `ByteStr`)
 - #141811 (Unimplement unsized_locals)
 - #142243 (float tests: deduplicate min, max, and rounding tests)
 - #142464 (variadic functions: remove list of supported ABIs from error)
 - #142477 (Fix incorrect suggestion when calling an associated type with a type anchor)
 - #142484 (Remove unneeded lifetime bound from signature of BTreeSet::extract_if)
 - #142489 (Update the `compiler-builtins` subtree)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 22f91ae into rust-lang:master Jun 14, 2025
10 checks passed
@rustbot rustbot added this to the 1.89.0 milestone Jun 14, 2025
rust-timer added a commit that referenced this pull request Jun 14, 2025
Rollup merge of #142484 - dtolnay:bsetextract, r=m-ou-se

Remove unneeded lifetime bound from signature of BTreeSet::extract_if

One way to observe the difference between these signatures, using 0 explicit lifetimes and 0 contrived where-clauses:

```rust
use std::collections::btree_set::{BTreeSet, ExtractIf};
use std::ops::RangeFull;

fn repro(
    set: &mut BTreeSet<i32>,
    predicate: impl Fn(i32) -> bool,
) -> ExtractIf<i32, RangeFull, impl FnMut(&i32) -> bool> {
    set.extract_if(.., move |x| predicate(*x))
}
```

**Before:**

```console
error[E0311]: the parameter type `impl Fn(i32) -> bool` may not live long enough
 --> src/lib.rs:8:5
  |
5 |     set: &mut BTreeSet<i32>,
  |          ------------------ the parameter type `impl Fn(i32) -> bool` must be valid for the anonymous lifetime defined here...
...
8 |     set.extract_if(.., move |x| predicate(*x))
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `impl Fn(i32) -> bool` will meet its required lifetime bounds
  |
help: consider adding an explicit lifetime bound
  |
4 ~ fn repro<'a>(
5 ~     set: &'a mut BTreeSet<i32>,
6 ~     predicate: impl Fn(i32) -> bool + 'a,
7 ~ ) -> ExtractIf<'a, i32, RangeFull, impl FnMut(&i32) -> bool> {
  |
```

**After:** compiles success.

- Tracking issue: #70530
RalfJung pushed a commit to RalfJung/miri that referenced this pull request Jun 15, 2025
Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#140593 (Temporary lifetime extension through tuple struct and tuple variant constructors)
 - rust-lang/rust#141399 ([rustdoc] Give more information into extracted doctest information)
 - rust-lang/rust#141493 (Delegate `<SocketAddr as Debug>` to `ByteStr`)
 - rust-lang/rust#141811 (Unimplement unsized_locals)
 - rust-lang/rust#142243 (float tests: deduplicate min, max, and rounding tests)
 - rust-lang/rust#142464 (variadic functions: remove list of supported ABIs from error)
 - rust-lang/rust#142477 (Fix incorrect suggestion when calling an associated type with a type anchor)
 - rust-lang/rust#142484 (Remove unneeded lifetime bound from signature of BTreeSet::extract_if)
 - rust-lang/rust#142489 (Update the `compiler-builtins` subtree)

r? `@ghost`
`@rustbot` modify labels: rollup
github-actions bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Jun 16, 2025
Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#140593 (Temporary lifetime extension through tuple struct and tuple variant constructors)
 - rust-lang/rust#141399 ([rustdoc] Give more information into extracted doctest information)
 - rust-lang/rust#141493 (Delegate `<SocketAddr as Debug>` to `ByteStr`)
 - rust-lang/rust#141811 (Unimplement unsized_locals)
 - rust-lang/rust#142243 (float tests: deduplicate min, max, and rounding tests)
 - rust-lang/rust#142464 (variadic functions: remove list of supported ABIs from error)
 - rust-lang/rust#142477 (Fix incorrect suggestion when calling an associated type with a type anchor)
 - rust-lang/rust#142484 (Remove unneeded lifetime bound from signature of BTreeSet::extract_if)
 - rust-lang/rust#142489 (Update the `compiler-builtins` subtree)

r? `@ghost`
`@rustbot` modify labels: rollup
github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this pull request Jun 18, 2025
Remove unneeded lifetime bound from signature of BTreeSet::extract_if

One way to observe the difference between these signatures, using 0 explicit lifetimes and 0 contrived where-clauses:

```rust
use std::collections::btree_set::{BTreeSet, ExtractIf};
use std::ops::RangeFull;

fn repro(
    set: &mut BTreeSet<i32>,
    predicate: impl Fn(i32) -> bool,
) -> ExtractIf<i32, RangeFull, impl FnMut(&i32) -> bool> {
    set.extract_if(.., move |x| predicate(*x))
}
```

**Before:**

```console
error[E0311]: the parameter type `impl Fn(i32) -> bool` may not live long enough
 --> src/lib.rs:8:5
  |
5 |     set: &mut BTreeSet<i32>,
  |          ------------------ the parameter type `impl Fn(i32) -> bool` must be valid for the anonymous lifetime defined here...
...
8 |     set.extract_if(.., move |x| predicate(*x))
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `impl Fn(i32) -> bool` will meet its required lifetime bounds
  |
help: consider adding an explicit lifetime bound
  |
4 ~ fn repro<'a>(
5 ~     set: &'a mut BTreeSet<i32>,
6 ~     predicate: impl Fn(i32) -> bool + 'a,
7 ~ ) -> ExtractIf<'a, i32, RangeFull, impl FnMut(&i32) -> bool> {
  |
```

**After:** compiles success.

- Tracking issue: rust-lang#70530
github-actions bot pushed a commit to rust-lang/compiler-builtins that referenced this pull request Jul 12, 2025
Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#140593 (Temporary lifetime extension through tuple struct and tuple variant constructors)
 - rust-lang/rust#141399 ([rustdoc] Give more information into extracted doctest information)
 - rust-lang/rust#141493 (Delegate `<SocketAddr as Debug>` to `ByteStr`)
 - rust-lang/rust#141811 (Unimplement unsized_locals)
 - rust-lang/rust#142243 (float tests: deduplicate min, max, and rounding tests)
 - rust-lang/rust#142464 (variadic functions: remove list of supported ABIs from error)
 - rust-lang/rust#142477 (Fix incorrect suggestion when calling an associated type with a type anchor)
 - rust-lang/rust#142484 (Remove unneeded lifetime bound from signature of BTreeSet::extract_if)
 - rust-lang/rust#142489 (Update the `compiler-builtins` subtree)

r? `@ghost`
`@rustbot` modify labels: rollup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants